﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace Kokomo.PeInspector.VisualStudioAdapter
{
	/// <summary>
	/// Represents a property within a <see cref="CSharpProject"/>.
	/// </summary>
	/// <remarks>
	/// Properties are grouped into a <see cref="PropertyGroup"/>.
	/// </remarks>
	[XmlRoot("dynamic")]
	public class Property
	{
		/// <summary>
		/// Initializes a new instance of <see cref="Property"/>.
		/// </summary>
		public Property()
		{
		}
		/// <summary>
		/// Initializes a new instance of <see cref="Property"/>.
		/// </summary>
		/// <param name="name">The name of the property.</param>
		public Property(string name)
		{
			this.Name = name;
		}

		/// <summary>
		/// Gets or sets the name of the property.
		/// </summary>
		public string Name { get; set; }
		/// <summary>
		/// Gets or sets the property condition.
		/// </summary>
		/// <remarks>
		/// The condition determines when the property becomes effective.
		/// </remarks>
		public string Condition { get; set; }
		/// <summary>
		/// Gets or sets the value of the property.
		/// </summary>
		public object Value { get; set; }

		public void WriteXml(System.Xml.XmlWriter writer)
		{
			writer.WriteStartElement(this.Name);
			if (this.Condition != null)
				writer.WriteAttributeString("Condition", this.Condition);
			if (this.Value != null)
				writer.WriteValue(this.Value.ToString());
			writer.WriteEndElement();
		}
	}
}
